package jdbc;

import java.sql.Connection;
import java.sql.PreparedStatement;

public class JDBCDemo14 {
    public static void main(String[] args) {
        try(Connection connection = DBUtil.getConnection();){

            connection.setTransactionIsolation(Connection.TRANSACTION_READ_COMMITTED);

            connection.setAutoCommit(false);

            String sql = "insert into userinfo (username,password,nickname,age) values (?,?,?,?)";

            PreparedStatement pr = connection.prepareStatement(sql);
            pr.setString(1,"李四");
            pr.setString(2,"123456");
            pr.setString(3,"老四");
            pr.setInt(4,18);

            int num = pr.executeUpdate();
            System.out.println(num > 0 ? "添加成功！" : "添加失败！");
//            connection.rollback();
            connection.commit();

        }catch (Exception e){
            e.printStackTrace();
        }
    }
}
